Repository navigation
fix: paint Android text decorations when a text update keeps the view's frame - #58847
Conversation
ReactTextView.onDraw paints CanvasEffectSpans (underline, strikethrough) only when getLayout() is non-null. TextView drops its Layout in setText and rebuilds it in onMeasure, and Fabric measures a view only when its frame changed, so a text state update that keeps the frame (a decoration or color change on a text of the same size) reaches onDraw with no Layout and the decorations are skipped until something else re-measures the view. Rebuild the Layout at the current size before painting; TextView.onDraw would build one for the plain text anyway.
7affdde to
f653a87
Compare
|
We're hitting this in production on 0.88.0: swapping a Text's content without changing its size drops the underline on nested Text until something re-measures the view. We've been shipping this PR as a local patch and it fixes it for us. Since it's a 0.88 regression from #56768, a review would be much appreciated so it can be picked into 0.88.x, like the related crash fixes #58366 and #59050 (picked for 0.88.1 in reactwg/react-native-releases#1456). |
|
@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D129144546. |
|
Another data point, from a production app rather than an animation: this reproduces on 0.87.1 with a plain colour change, no Reanimated involved. Trigger: a Environment: react-native 0.87.1, New Architecture, Android 16 (API 36), 1080×2400 @420dpi emulator. Measured by sampling the underline row across the label width (317px-wide label):
Every glyph row is byte-identical between the first frame and the released frame; only the two decoration rows change. It is not specific to press. A Fast Refresh that changes only the component's style leaves the underline missing in the resting state as well, which matches this PR's "text update keeps the view's frame" framing. Two things that may be useful:
Is there a plan to pick this into 0.88.x or 0.89? #58579 was closed in favour of this PR in October, and this is currently the only thing tracking the issue, so anyone on a released version has no fix available. |
|
Thanks, you're right about the range, and my "0.88 regression" above was wrong. #56768 landed on 4 June and shipped in 0.87.0; On the crash, I'd expect it on 0.87.1 too, just not with that repro.
|
javache
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
This pull request was successfully merged by @tshmieldev in 7b6e790 When will my fix make it into a release? | How to file a pick request? |
|
Thanks for landing this. To answer the question above: I've filed pick requests for 0.88 (reactwg/react-native-releases#1542) and 0.89 (reactwg/react-native-releases#1543). The commit applies cleanly to |
This is #58579 by @MatiPl01, a fix for a bug I found. Mati is no longer at Software Mansion, so I'm picking this up from my fork. Thanks Mati!
Summary:
Since #56768 underline and strikethrough are painted by
ReactTextView.onDrawthroughCanvasEffectSpans, and only whengetLayout()is non-null.TextView.setTextdrops theLayoutand rebuilds it inonMeasure, but Fabric measures a view only when its frame changed. A text update that keeps the frame (textDecorationLineortextDecorationColorchanging on a text that keeps its size) therefore reachesonDrawwithout aLayout, the decorations are skipped andsuper.onDraw()paints plain text; they show up only once something else re-measures the view.onDrawnow rebuilds theLayoutat the current size before painting the effects;TextView.onDrawwould build one for the text anyway.Changelog:
[ANDROID] [FIXED] - Draw text decorations after a text update that did not change the view's frame
Test Plan:
Android emulator API 34, RN 0.88.0-rc.1. With logging in
onDraw, every frame-preserving update arrived assetText -> onDrawwithgetLayout() == nulland no decoration painted, both forsetStatetogglingtextDecorationLineand for a Reanimated animation updating it every frame; the same update followed by a frame change painted it.textDecorationLinecyclingnone/underline/line-through/underline line-throughevery 0.75 s, before and after:before-after-android-textDecorationLine.mp4